#include "prompt.h"
#include "defs.h"
#include "kc.h"
#include "video.h"

extern char * video;
extern int screen_pos;
int commNum= 0;
unsigned char buffer[MAX_COMM][COMM_LEN];

void 
process_comand(int init, int end)	/* Me fijo que comando ingreso el usuario */
{
	static char chat[] = "chat";
	static char help[] = "help";
	static char notValidComm[] = "Error: not a valid command. Try 'help'.";
	
	if( !mystrcmp(video+init, (end - init)/2+1, chat) )
		putChar('!');

	else if( !mystrcmp(video+init, (end - init)/2+1, help) )
		printHelp();
	else
		myprint(notValidComm, 1);
	cpyBuff(video+init, (end - init)/2+1);
	return;
}

int
mystrcmp(char * string1, int string1len, char * string2)
{
	int i, error= 0;
	
	for( i= 0; i < string1len && *string2 != '\0' && !error; i++ )
	{
		if( *string1 != *string2++ )
			error= 1;
		string1+= 2;
	}
	if( *string2 != '\0' || i < string1len )
		error= 1;
	
	return error;
}

void
cpyBuff(char * string, int stringlen)  /* Copio la linea al buffer de history */
{
	int i;

	for( i= 0; i < stringlen; i++, string+=2 )
		buffer[commNum][i]= *string;
	buffer[commNum][i]= '\0';
	commNum++;
	return;
}
